package edu.hunau.cxb19.oop.class12;

import java.util.Arrays;
import java.util.Scanner;

import org.junit.Test;

import edu.hunau.cxb19.oop.class12.ex.Counter;

/**
 *
 * @author hb
 *
 *         2020-03-11 14:42:50
 */
public class CounterTest {

	@Test
	public void test() {
		Scanner sc = new Scanner(System.in);
		String datas = sc.nextLine();
		Counter[] arr = parse(datas);
		System.out.println(Arrays.toString(arr));
	}

	/**
	 * 获得每个字符出现的次数
	 * 
	 * @param datas
	 * @return
	 */
	public Counter[] parse(String datas) {
		Counter[] result = new Counter[0];
		for (int i = 0; i < datas.length(); i++) {
			char c = datas.charAt(i);
			Counter counter = new Counter(c, 1);
			// 判定当前的字符是否已经出现
			boolean flag = false;
			for (int j = 0; j < result.length; j++) {
				if (result[j].equals(counter)) { // if(result[i].getC()==coutner.getC())
					// 将数据加1
					result[j].setNumber(result[j].getNumber() + 1);
					flag = true;
					break;
				}
			}

			if (!flag) {
				// 扩容添加数据
				result = Arrays.copyOf(result, result.length + 1);
				result[result.length - 1] = counter;
			}

		}

		return result;

	}
}
